<style lang="less">
    @import "./style/userInfo.less";
</style>
<template>
    <div class="page user-info">
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_bd weui_cell_primary">头像</div>
                <div class="weui_cell_ft"><img class="avatar" v-bind:src="serverData.head|imgBase"></div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">昵称</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <div class="text-input">{{serverData.name}}</div>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">性别</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <div class="text-input">{{gender}}</div>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label for="" class="weui_label">生日</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="date" v-model="serverData.birth|dataFormat"/>
                </div>
            </div>
        </div>
        <msg :data="errorData"></msg>
    </div>
</template>

<script type="text/ecmascript-6">
    import {getSession,setSession} from '../lib/session'
    import {imgBase} from '../lib/args'
    import server from '../lib/server'
    import Msg from '../components/Msg.vue'
    export default {
        filters:{
            imgBase,
            dataFormat:{
                read(val){
                    if(new Date(val)=='Invalid Date'){
                        return;
                    }
                    return val;
                },
                write(val){
                    return val;
                }
            }
        },
        data () {
            return {
                contactOptions: ['女','男','未设置'],
                serverData:getSession(),
                errorData:{}
            }
        },
        computed:{
            gender(){
                if(this.serverData.gender==0){
                    return '女';
                }else if(this.serverData.gender==1){
                    return '男';
                }else{
                    return '未设置';
                }
            }
        },
        ready(){
            this.$watch('serverData.birth',(val)=>{
                server('/P/U/SetUserInfo_WX',{
                    session_id:this.serverData.session_id,
                    birth:val
                }).success((response)=>{
                    if(response.code==1){
                        setSession(this.serverData);
                    }else{
                        if(response.code==19){
                            this.errorData={
                                show:true,
                                type:'login'
                            };
                        }else{
                            this.errorData={
                                show:true,
                                type:'error',
                                msg:response.msg
                            };
                        }
                    }
                });
            });
        },
        components:{
            Msg
        },
        methods:{
        },
        created () {
        },

        destroyed () {
        }
    }
</script>
